<?php

/*
 * Register.php
 * Henrik Volckmer
 */

require_once('./includes/config.php');
require_once('./includes/database.php');
require_once('./includes/session.php'); 
require_once('./includes/users.php');
require_once('./includes/smarty/Smarty.class.php');

db_setup();
session_continue();
	
$smarty = new Smarty();
$smarty->assign('root_folder',$root_folder);

if (isset($_POST['username']))
{
	$smarty->assign('reg_attempt', true);
	
	if (isset($_POST['displayname']) 	&&
		isset($_POST['password'])		&&
		isset($_POST['email']))
	{
		if (!user_exists($_POST['username']))
		{	
			if (create_user(mysql_real_escape_string($_POST['username']), 
							mysql_real_escape_string($_POST['displayname']), 
							mysql_real_escape_string($_POST['password']),
							mysql_real_escape_string($_POST['email'])))
			{
				$smarty->assign('reg_success', true);
			}
			else
			{
				$smarty->assign('reg_success', false);
			}
		}
		else
		{
			$smarty->assign('reg_success', false);
		}
	}
}
else
{
	$smarty->assign('reg_attempt', false);
}

$smarty->display('register.tpl');

?>